package org.mzx.shortLink.adminn.common.Serializer;

import cn.hutool.core.util.DesensitizedUtil;
import com.fasterxml.jackson.core.JsonGenerator;
import com.fasterxml.jackson.databind.JsonSerializer;
import com.fasterxml.jackson.databind.SerializerProvider;

import java.io.IOException;

public class PhoneDesensitizationSerializer extends JsonSerializer<String> {

    /**
     * 手机号的脱敏处理18331131646 - > 183******1646
     * */

    @Override
    public void serialize(String phone, JsonGenerator jsonGenerator, SerializerProvider serializerProvider) throws IOException {
        String phoneDesensitization = DesensitizedUtil.mobilePhone(phone);
        //DesensitizedUtil.mobilePhone是直接调用的工具包的方法，省的写了
        jsonGenerator.writeString(phoneDesensitization);
    }
}
